package com.example.aop.proxy;

//静态代理类

/**
 * 1.每个接口一个代理类（自己编写）
 * 2.灵活性低
 */
public class OrderServiceProxy implements OrderService{
    private OrderService orderService;
    public OrderServiceProxy(OrderService orderService){
        this.orderService = orderService;
    }
    @Override
    public void createOrder() {
        long startTime = System.currentTimeMillis();
        System.out.println("【静态代理】开始记录日志");
        orderService.createOrder(); // 调用真实方法
        long endTime = System.currentTimeMillis();
        System.out.println("【静态代理】日志结束，耗时：" + (endTime - startTime) + "ms");
    }

    @Override
    public String queryOrder(int orderId) {
        System.out.println("【静态代理】开始记录日志");
        String result = orderService.queryOrder(orderId);
        System.out.println("【静态代理】日志结束");
        return result;
    }
}
